using System;
using MessagePack;
using MessagePack.Formatters;

namespace Mytek.Messenger.Serializers.MessagePackSerializer
{
    /// <summary>
    /// 序列化日期时间格式转换
    /// </summary>
    public class DurableDateTimeFormatter : IMessagePackFormatter<DateTime>
    {
        public DateTime Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
        {
            return new DateTime(reader.ReadInt64());
        }

        public void Serialize(ref MessagePackWriter writer, DateTime value, MessagePackSerializerOptions options)
        {
            writer.Write(value.Ticks);
        }
    }
}